package com.it.myh.read;

import com.it.myh.query.probability.TimeZone;

import java.io.Serializable;
import java.time.LocalTime;
import java.util.List;

/**
 * @Description: // 类说明，在创建类时要填写
 * @ClassName: LocationAndTime    // 类名，会自动填充
 * @Author: MYH          // 创建者
 * @Date: 2023/6/18 17:49   // 时间
 * @Version: 1.0     // 版本
 */
public class LocationAndTime implements Serializable {

    private static final double TOLERANCE = 0.0001; // 容差值，误差在几十米之内，精确度高。

    private static final long serialVersionUID = -6783279540439473626L;

    private Double latitude; //纬度

    private Double longitude;//经度

    private LocalTime time;//日期与时间

    private Integer num;//出现的次数

    private Double probability;//访问概率

    private TimeZone timeZone;

    public LocationAndTime() {
    }

    public LocationAndTime(Double latitude, Double longitude, LocalTime time) {
        this.latitude = latitude;
        this.longitude = longitude;
        this.time = time;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public LocalTime getTime() {
        return time;
    }

    public void setTime(LocalTime time) {
        this.time = time;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public Double getProbability() {
        return probability;
    }

    public void setProbability(Double probability) {
        this.probability = probability;
    }

    public TimeZone getTimeZone() {
        return timeZone;
    }

    public void setTimeZone(TimeZone timeZone) {
        this.timeZone = timeZone;
    }

    @Override
    public String toString() {
        return "latitude=" + latitude +
                ";longitude=" + longitude +
                ";time=" + time +
                ";num=" + num +
                ";probability=" + probability; //+ ";" +  timeZone;
    }

    //判断两个位置是否为同一个位置
    public static boolean isSameLocation(LocationAndTime l1, LocationAndTime l2){
        double latDiff = Math.abs(l1.latitude - l2.latitude);
        double lonDiff = Math.abs(l1.longitude - l2.longitude);
        return latDiff <= TOLERANCE && lonDiff <= TOLERANCE;
    }
    //返回相同的位置
    public static LocationAndTime returnSameLocation(LocationAndTime location, List<LocationAndTime> locationAndTimes){
        TimeZone realTimeZone = TimeZone.whichZone(location.getTime());
        for (LocationAndTime locationAndTime : locationAndTimes) {
            TimeZone zone = TimeZone.whichZone(locationAndTime.getTime());
            if (isSameLocation(location,locationAndTime) && TimeZone.isSameTimeZone(realTimeZone,zone)){
                return locationAndTime;
            }
        }
        return null;
    }

}
